//
//  BCProjectDetailSourceModel.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/22.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "BCProjectDetailSourceModel.h"

#import "BCProjectDetailResponse.h"


//////////////////////////////// 参与规则model ///////////////////////////////////////////////////
@implementation BCProjectDetailJoinRuleModel


@end
////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////// 产品介绍model ///////////////////////////////////////////////////
@implementation BCProjectDetailIntroductionModel

@end
////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////// 常见问题model ///////////////////////////////////////////////////
@implementation BCProjectDetailCommonProblemModel

@end
////////////////////////////////////////////////////////////////////////////////////////////////

@implementation BCProjectDetailSectionModel

- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

@end


@interface BCProjectDetailSourceModel ()

@property (nonatomic, strong) BCProjectDetailSectionModel *projectData;
@property (nonatomic, strong) BCProjectDetailSectionModel *joinPeople;
@property (nonatomic, strong) BCProjectDetailSectionModel *riches;
@property (nonatomic, strong) BCProjectDetailSectionModel *joinRules;
@property (nonatomic, strong) BCProjectDetailSectionModel *intrduction;
@property (nonatomic, strong) BCProjectDetailSectionModel *instruction;
@property (nonatomic, strong) BCProjectDetailSectionModel *commonProblems;

@end

@implementation BCProjectDetailSourceModel

- (BCProjectDetailSectionModel *)projectData {
    if (!_projectData) {
        _projectData = [BCProjectDetailSectionModel new];
        _projectData.sectionType = BCProjectDetailSectionTypeProjectData;
        _projectData.placeholderNumbres = 1;
    }
    return _projectData;
}

- (BCProjectDetailSectionModel *)joinPeople {
    if (!_joinPeople) {
        _joinPeople = [BCProjectDetailSectionModel new];
        _joinPeople.sectionType = BCProjectDetailSectionTypeJoinPeoples;
        _joinPeople.placeholderNumbres = 1;
    }
    return _joinPeople;
}

- (BCProjectDetailSectionModel *)riches {
    if (!_riches) {
        _riches = [BCProjectDetailSectionModel new];
        _riches.sectionType = BCProjectDetailSectionTypeRiches;
    }
    return _riches;
}
- (BCProjectDetailSectionModel *)joinRules {
    if (!_joinRules) {
        _joinRules = [BCProjectDetailSectionModel new];
        _joinRules.sectionType = BCProjectDetailSectionTypeJoinRules;
        _joinRules.placeholderNumbres = 3;
    }
    return _joinRules;
}
- (BCProjectDetailSectionModel *)intrduction {
    if (!_intrduction) {
        _intrduction = [BCProjectDetailSectionModel new];
        _intrduction.sectionType = BCProjectDetailSectionTypeProjectIntrduction;
        _intrduction.placeholderNumbres = 1;
        _intrduction.detailButtonImageName = @"project_intrduction_img";
    }
    return _intrduction;
}
- (BCProjectDetailSectionModel *)instruction {
    if (!_instruction) {
        _instruction = [BCProjectDetailSectionModel new];
        _instruction.sectionType = BCProjectDetailSectionTypeInstruction;
        _instruction.needRightArrow = true;
        _instruction.canClick = true;
    }
    return _instruction;
}
- (BCProjectDetailSectionModel *)commonProblems {
    if (!_commonProblems) {
        _commonProblems = [BCProjectDetailSectionModel new];
        _commonProblems.sectionType = BCProjectDetailSectionTypeCommonProblems;
        _commonProblems.needRightArrow = true;
        _commonProblems.canClick = true;
        _commonProblems.placeholderNumbres = 2;
    }
    return _commonProblems;
}


- (NSMutableArray<BCProjectDetailSectionModel *> *)sectionSource {
    if (!_sectionSource) {
        _sectionSource = [NSMutableArray array];
        //
        [_sectionSource addObject:self.projectData];
        [_sectionSource addObject:self.joinPeople];
        [_sectionSource addObject:self.riches];
        [_sectionSource addObject:self.joinRules];
        [_sectionSource addObject:self.intrduction];
        [_sectionSource addObject:self.instruction];
        [_sectionSource addObject:self.commonProblems];
    }
    return _sectionSource;
}


- (void)setIsHandleData:(BOOL)isHandleData {
    _isHandleData = isHandleData;
    //
    self.projectData.isHandleData = isHandleData;
    self.joinPeople.isHandleData = isHandleData;
    self.riches.isHandleData = isHandleData;
    self.joinRules.isHandleData = isHandleData;
    self.intrduction.isHandleData = isHandleData;
    self.instruction.isHandleData = isHandleData;
    self.commonProblems.isHandleData = isHandleData;
}




- (void)handleData {
    self.isHandleData = true;
    
    //处理介绍
    [self.intrduction.dataSource removeAllObjects];
    BCProjectDetailIntroductionModel *introduction = [BCProjectDetailIntroductionModel new];
    introduction.introduction = @"RA级低风险\n本参与属于低风险产品，收益稳定风险可控。";
    [self.intrduction.dataSource addObject:introduction];
    
    //常见问题
    [self.commonProblems.dataSource removeAllObjects];
    BCProjectDetailCommonProblemModel *problem1 = [BCProjectDetailCommonProblemModel new];
    problem1.question = @"我投入的BTC/ETH什么时候可以获得回报？";
    problem1.answer = @"在下一轮资金募集完毕后立即发放本轮投入和利息。";
    [self.commonProblems.dataSource addObject:problem1];
    BCProjectDetailCommonProblemModel *problem2 = [BCProjectDetailCommonProblemModel new];
    problem2.question = @"没有募集满的那一轮我的BTC/ETH什么时候退回？";
    problem2.answer = @"时间到期后，我们将在1个小时内给予全额无息退回到账户。";
    [self.commonProblems.dataSource addObject:problem2];
    BCProjectDetailCommonProblemModel *problem3 = [BCProjectDetailCommonProblemModel new];
    problem3.question = @"如果视图不正确显示，请赶快提出，以免体验效果不佳";
    problem3.answer = @"视图到处显示都不正确，是否需要全部修改，我晕哦😯";
    [self.commonProblems.dataSource addObject:problem3];
    
    //参与规则
    [self.joinRules.dataSource removeAllObjects];
    BCProjectDetailJoinRuleModel *rule_1 = [BCProjectDetailJoinRuleModel new];
    rule_1.title = @"购买时间";
    rule_1.content = @"项目开始24小时内";
    [self.joinRules.dataSource addObject:rule_1];
    BCProjectDetailJoinRuleModel *rule_2 = [BCProjectDetailJoinRuleModel new];
    rule_2.title = @"回报率";
    rule_2.content = @"1%";
    [self.joinRules.dataSource addObject:rule_2];
    BCProjectDetailJoinRuleModel *rule_3 = [BCProjectDetailJoinRuleModel new];
    rule_3.title = @"到账时间";
    rule_3.content = @"T+1；T指轮数";
    [self.joinRules.dataSource addObject:rule_3];
    BCProjectDetailJoinRuleModel *rule_4 = [BCProjectDetailJoinRuleModel new];
    rule_4.title = @"风险阈值";
    rule_4.content = @"90%";
    rule_4.details = @"(倘若下一轮直接无法凑齐则返回90%的资金)";
    [self.joinRules.dataSource addObject:rule_4];
    BCProjectDetailJoinRuleModel *rule_5 = [BCProjectDetailJoinRuleModel new];
    rule_5.title = @"字数过长测试标题";
    rule_5.content = @"此标题有8个字符长度";
    rule_5.details = @"(若此方式显示视图不佳，请尽早提出修改，谢谢！🙏🙏🙏)";
    [self.joinRules.dataSource addObject:rule_5];
    
    //处理projectData时 由于只有一个所以没有model 只需要在dataSource中随意加一个为nil的对象即可
    [self.projectData.dataSource removeAllObjects];
    [self.projectData.dataSource addObject:@(self.isHandleData)];
    //参与人数同 projectData
    [self.joinPeople.dataSource removeAllObjects];
    [self.joinPeople.dataSource addObject:@(self.isHandleData)];
    //
    [self.riches.dataSource removeAllObjects];
    [self.riches.dataSource addObject:@(self.isHandleData)];
    
}

- (void)handleData:(BCProjectDetailData *)data {
    //项目信息
    //处理projectData时 由于只有一个所以没有model 只需要在dataSource中随意加一个为nil的对象即可
    [self.projectData.dataSource removeAllObjects];
    [self.projectData.dataSource addObject:@(self.isHandleData)];
    //参与人数同 projectData
    [self.joinPeople.dataSource removeAllObjects];
    if (data.data.join_num) {//如果没有参与人数不显示
        [self.joinPeople.dataSource addObject:@(self.isHandleData)];
    }
    //
    [self.riches.dataSource removeAllObjects];
    if (data.tags.data.count) {//如果没有数据不显示
        [self.riches.dataSource addObject:@(self.isHandleData)];
    }
    //参与规则
    [self.joinRules.dataSource removeAllObjects];
    self.joinRules.sectionTitle = data.rule.title;
    NSArray *rules = data.rule.data;
    if (rules.count) {
        for (int i=0; i<rules.count; i++) {
            BCProjectDetailDataRuleData *rule = rules[i];
            //
            BCProjectDetailJoinRuleModel *joinRule = [BCProjectDetailJoinRuleModel new];
            joinRule.title = rule.title;
            joinRule.content = rule.repay;
            joinRule.details = rule.notes;
            [self.joinRules.dataSource addObject:joinRule];
        }
    }
    //产品介绍
    [self.intrduction.dataSource removeAllObjects];
    self.intrduction.sectionTitle = data.introduce.title;
    //拼接产品介绍的风险
    BCProjectDetailDataIntroductionRiskDefine *risk;
    NSArray *riskDefins = data.introduce.risk_define;
    if (riskDefins.count) {
        for (BCProjectDetailDataIntroductionRiskDefine *model in riskDefins) {
            if ([model.sign isEqualToString:data.introduce.sign]) {
                risk = model;
                break;
            }
        }
    }
    NSString *riskString = data.introduce.sign;
    if (risk) {
        riskString = [NSString stringWithFormat:@"%@%@",risk.shot,risk.risk];
    }
    riskString = [riskString stringByAppendingFormat:@"\n%@",data.introduce.docs];
    //
    BCProjectDetailIntroductionModel *introduction = [BCProjectDetailIntroductionModel new];
    introduction.introduction = riskString;
    [self.intrduction.dataSource addObject:introduction];
    
    //产品说明
    self.instruction.sectionTitle = data.explain.title;
    self.instruction.sectionDetails = data.explain.docs;
    self.instruction.sectionURL = data.explain.url;
    //常见问题
    [self.commonProblems.dataSource removeAllObjects];
    self.commonProblems.sectionTitle = data.problem.title;
    self.commonProblems.sectionURL = data.problem.url;
    NSArray *prolems = data.problem.main;
    if (prolems.count) {
        for (int i=0; i<prolems.count; i++) {
            BCProjectDetailDataProblemMain *problem = prolems[i];
            //
            BCProjectDetailCommonProblemModel *custom = [BCProjectDetailCommonProblemModel new];
            custom.question = problem.q;
            custom.answer = problem.a;
            [self.commonProblems.dataSource addObject:custom];
        }
    }
    //
}

@end
